<template>
	<view class="page">
		<!-- 内容 -->
		<view class="content">
			<view class="title">
				公司信息
			</view>
			<view class="prompt">
				拍摄并上传营业执照，更新公司信息
			</view>
			<view style="margin:32rpx 0 22rpx 0">
				<upload-image type="business" :defaultList="formData.frontdefaultList" @uploaded="uploadedBusiness"></upload-image>
			</view>
			<view class="fui-wrap">
				<fui-form ref="FormRef" top="0" :model="formData">
					<fui-form-item label="社会信用代码" labelWeight="600" labelWidth="200" :left="0" labelSize="28"
						prop="code">
						<fui-input disabled :borderBottom="false"  color="#333333" size="28" :padding="[0]"
							placeholder="请输入社会信用代码" v-model="formData.code"></fui-input>
					</fui-form-item>
					<fui-form-item label="法人姓名" labelWeight="600" labelWidth="200" :left="0" labelSize="28" prop="name">
						<fui-input disabled :borderBottom="false" color="#333333" size="28" :padding="[0]" placeholder="请输入法人姓名"
							v-model="formData.name"></fui-input>
					</fui-form-item>
					<fui-form-item label="公司名称" labelWeight="600" labelWidth="200" :left="0" labelSize="28"
						prop="corporatename">
						<fui-input disabled :borderBottom="false" color="#333333" size="28" :padding="[0]" placeholder="请输入公司名称"
							v-model="formData.corporatename"></fui-input>
					</fui-form-item>

					<fui-form-item label="公司地址" labelWeight="600" :left="0" labelWidth="200" labelSize="28"
						prop="corporateaddress">
						<fui-input disabled :borderBottom="false" color="#333333" size="28" :padding="[0]" placeholder="请输入公司地址"
							v-model="formData.corporateaddress"></fui-input>
					</fui-form-item>
					<fui-form-item :bottomBorder="false" label="公司描述" labelWeight="600" :left="0" labelWidth="200"
						class="textarea-box" labelSize="28" prop="describe">
						<fui-textarea maxlength="200" size="28" color="#333333" :isCounter="true" radius="16"
							borderColor="#DFDFDF" v-model="formData.describe" placeholder="请输入公司描述" textareaBorder
							:marginTop="16"></fui-textarea>
					</fui-form-item>
				</fui-form>
			</view>
			<!-- 底部按钮 -->
			<view class="btn">
				<fui-button :disabled="false" disabledBackground="#DFDFDF" borderColor="var(--fui-color-primary)" width="312rpx"
					height="78rpx" background="#FFFFFF"  @click="cancellation" color="var(--fui-color-primary)">取消</fui-button>
				<fui-button :disabled="false" width="312rpx" height="78rpx" disabledBackground="#DFDFDF"
					background="var(--fui-color-primary)"  @click="submit">下一步</fui-button>
			</view>
		</view>
	</view>
</template>

<script setup>
	import uploadImage from '@/components/upload/image'
	import SystemApi from '@/api/system.js'
	import {
		ref,inject
	} from 'vue'
	import {
		onLoad
	} from "@dcloudio/uni-app";
	const modal = inject('$modal')
	const FormRef = ref(null)
	const rules = ref([{
		name: "corporatename",
		rule: ["required"],
		msg: ["请输入公司名称"]
	}, {
		name: "code",
		rule: ["required", "minLength:18"],
		msg: ["请输入社会信用代码", "请输入正常的信用社代码"]
	}, {
		name: "corporateaddress",
		rule: ["required"],
		msg: ["请输入公司地址"]
	}, {
		name: "describe",
		rule: ["required"],
		msg: ["请输入公司描述"]
	}, {
		name: "name",
		rule: ["required"],
		msg: ["请输入法人姓名"]
	}])
	const formData = ref({
		corporatename: '',
		code: '',
		corporateaddress: '',
		describe: '',
		name: '',
		frontdefaultList:[],
	})
	onLoad((option) => {
		let obj = JSON.parse(decodeURIComponent(option.data))
		formData.value.corporatename = obj.title
		formData.value.code = obj.code
		formData.value.corporateaddress = obj.address
		formData.value.describe = obj.description
		formData.value.name = obj.corporateName
		formData.value.frontdefaultList.push(obj.businessLicense)
	});
	const changecycle = ((index) => {
		currentindex.value = index
	})
	// 上传
	const uploadedBusiness = async(e) => {
		if (e[0]) {
			const res = await SystemApi.uploadbusinessLicense({
				imageUrl: e[0]
			})
			if (res.code == 0) {
				let obj = JSON.parse(res.data)
				formData.value.businessurl = e[0]
				formData.value.corporatename = obj['单位名称']
				formData.value.code = obj['社会信用代码']
				formData.value.corporateaddress = obj['地址']
				formData.value.name = obj['法人']
			}
		}
	}
	// 下一步
	const submit = (async () => {
		const validRes = await FormRef.value.validator(formData.value, rules.value)
		if (validRes.isPassed) {
			uni.setStorageSync('editbusinessLicense',formData)
			uni.navigateTo({
				url:'./legalPerson'
			})
		}
	})
	const cancellation = (()=>{
		
	})
</script>

<style lang="scss" scoped>
	.content {
		margin: 36rpx;

		.title {
			font-size: 40rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			color: #333333;
		}

		.prompt {
			font-size: 24rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			color: #999999;
			margin-top: 20rpx;
		}

		::v-deep.fui-form__wrap-inner {
			padding: 0 !important;
		}

		::v-deep.fui-input__self {
			font-weight: bold;
		}

		.btn {
			padding-bottom: 118rpx;
			display: flex;
			align-items: center;
			justify-content: space-around;
			margin-top: 52rpx;
		}

		::v-deep.uni-textarea-textarea {
			font-weight: bold;
		}

		::v-deep.textarea-box .fui-form__wrap-inner {
			display: initial !important;
		}
		.fui-toast__custom {
			width: 594rpx;
			height: 352rpx;
			padding: 42rpx 18rpx 0 18rpx;
			box-sizing: border-box;

			.toast {
				width: 128rpx;
				height: 128rpx;
				margin: 0 auto;
				background-color: #FFFFFF;
				border-radius: 50%;
				margin-bottom: 42rpx;
				image {
					width: 100%;
					height: 100%;
					display: block;
				}
			}

			.fui-toast__txt {
				font-size: 32rpx;
				font-weight: 400;
				color: #FFFFFF;
				text-align: center;
				padding-bottom: 8rpx;
			}
			
		}

	}
</style>